<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
  <meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Sven Tafvelin">
  <meta name="GENERATOR"
 content="Mozilla/4.6 [en] (WinNT; I) [Netscape]">
  <title>Unix internt - Laboration 3</title>
</head>
<body>
Department of computer science and engineering &nbsp; &nbsp; &nbsp;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
2010-04-21<br>
Chalmers &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Unix internals<br>
ST/AD<br>
&nbsp;<br>
&nbsp;
<h2>Laboratory assignment&nbsp; 3 -&nbsp; Filesystem</h2>
<h4>Purpose</h4>
<ul>
To investigate a filesystem.
</ul>
<h4>Local&nbsp; filsystem</h4>
<ul>
This exercise must be done on a computer with a local file system.
</ul>
<h4><big>Assignment:</big></h4>
<ul>
  <ol>
    <li>Investigate with the <span style="font-style: italic;">mount</span>
command what the file system on your computer looks like. How is the
tree of&nbsp; different mounted filesystems put together? Which parts
are local and which parts are fetched over the network. Which special
purpose filesystems exist?<br>
    </li>
    <li>Write a&nbsp; C program that duplicates some of the functions
of the Linux <span style="font-style: italic;">stat(1)</span> command.
The program should take the name of a file as parameter and do <span
 style="font-style: italic;">stat(2)</span> or <span
 style="font-style: italic;">lstat(2)</span> on this file. The results
should be written to the terminal in a suitable formate (hexadecimal is
probabely best) for analyzing the file status. Use this program on
simple files, directories, special files and symbolic links to find out
the differences between them.<br>
    </li>
    <li>Write a C program that creates a file and writes 100 bytes with
known content (not binary zero), seeks to position 40000 and writes
another 100 bytes of nonzero data. After this the file is closed and
the program terminated. This program creates a file with a "hole" in
it. Create such a file in the local filesystem. Use the command <span
 style="font-style: italic;">od</span> to list the content of the file.
Run <span style="font-style: italic;">ls -l</span> and take note of
the length of the file. Use the program from step 2 to check the&nbsp;
lenght of the file and how many blocks the file use. Do the results
agree with the theory? Write a simple copying program that copies the
file by reading and writing one character in a loop until end-of-file.
Copy the file with the "hole" to new file with your copying program. Do
the same checks as previously on the copied file. What have happened?
Copy the file with the "hole" to a new file using the <span
 style="font-style: italic;">cp</span> command. Do the same checks
again. What have happened?<br>
    </li>
    <li>Write a C program that searches the local filesystem tree and
gathers information about all the files. The information is used to
calculate the wasted space as a function of block size and to recreate
table 8.12 (page 367) from the course book. To calculate data waste for
different block sizes, the calculation must be done for every file as
the filesystem is searched and summed up for each block size. The
filesystem on the lab machines (Reiserfs) is different from the BSD
file system. This do not matter if only the size of each file is used
to calculate the waste for every block size. Assume that every file and
directory requires one inode and that the size of the inode is 128
bytes. You must avoid searching NFS filesystems because there are too
many files there and it would generate to high load at the file server.
There are also some other special filesystems that should be avoided.
Only "normal" file systems should be searched. One way to avoid the
unwanted filesystems is to make a list of the beginning path name
component of these filesystems that the program use to avoid them.
Also, you should not follow symbolic links! Because it is difficult to
get everything correct from the beginning, the program should use two
arguments to limit the search. The first argument gives the total
number of files to search and the second argument indicates how often
information about the current file name should be written to the
terminal. For example &nbsp; <span style="font-style: italic;">&lt;program_name
100 1&gt;</span>&nbsp; means that 100 files are processed and
information is written for every file.&nbsp;&nbsp; <span
 style="font-style: italic;">&lt;program_name 1000 50&gt;</span>&nbsp;
means that 1000 files are processed and information is written for
every 50:th file. When everything works both values are set high for
the final run. Check that your results are reasonable and try to
explain any differences between your values and the values from the
book.<br>
    </li>
  </ol>
</ul>
<h4><big>Reporting:</big></h4>
<div style="margin-left: 40px;">Written documentation of your results
including commented program listings. Exercises 3 and 4&nbsp; should be
demonstrated for a course assistant. The documentation of exercise 4
should include a table like table 8.12 in the course book,
showing&nbsp; your results and a short evaluation of&nbsp; your results.<br>
</div>
<br>
</body>
</html>
